package com.yy.job.console.converter;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;

import com.yy.job.common.dao.po.YYJobStepDO;
import com.yy.job.common.enums.JobStepStatusEnum;
import com.yy.job.common.utils.date.YYDateUtils;
import com.yy.job.console.dto.JobStepView;

public class JobStepViewConverter {
	
	public static JobStepView convert(YYJobStepDO jobDO) {
		JobStepView consoleDTO = new JobStepView();
		BeanUtils.copyProperties(jobDO, consoleDTO);
		JobStepStatusEnum findByCode = JobStepStatusEnum.findByCode(jobDO.getStepStatus());
		if(findByCode !=null) {
			consoleDTO.setStepStatusName(findByCode.getName());
		}
		consoleDTO.setExecTimeFormat(YYDateUtils.formatDateTimeDefault(jobDO.getExecTime()));
		return consoleDTO;
	}
	
	public static List<JobStepView> listConvert(List<YYJobStepDO> jobDOs) {
		if (jobDOs == null) {
			return null;
		}
		return jobDOs.stream().map(e -> convert(e)).collect(Collectors.toList());
	}
	
}
